<?php
/**
 * TinyCorePHP
 * tiny but core php mvc framework
 * @author 	kelecode@gmail.com
 * @date 	2012-11-21
 */

define('TINY_VERSION','0.3');
define('TINY_RELEASE','20140101');

//error_reporting(0);
set_magic_quotes_runtime(0);

$startTime = microtime(true);

!defined('IN_SITE') && define('IN_SITE',true);
!defined('APP_ROOT') && define('APP_ROOT', str_replace('\\','/',dirname(__FILE__)));

require_once 'config.php';
require_once 'common.php';
require_once 'functions.php';
require_once 'plugin.php';
require_once 'db.class.php';
require_once 'control.class.php';
require_once 'model.class.php';

unset($GLOBALS, $_ENV, $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS, $HTTP_SERVER_VARS, $HTTP_ENV_VARS);
$_GET = daddslashes($_GET, 1, TRUE);
$_POST = daddslashes($_POST, 1, TRUE);
$_COOKIE = daddslashes($_COOKIE, 1, TRUE);
$_SERVER = daddslashes($_SERVER);
$_FILES = daddslashes($_FILES);
$_REQUEST = daddslashes($_REQUEST, 1, TRUE);

class Tiny{

	public function run(){
		$component = trim(getgpc('com'));
		$control = trim(getgpc('c'));
		$method = trim(getgpc('m'));
		$control = empty($control) ? 'index' : $control;
		$method = empty($method) ? 'index' : $method;
		$className = ucfirst($control).'Control';
		$file = APP_ROOT . (! empty($component) ? '/component/com_' . strtolower($component) : '') . '/control/' . $className . '.class.php';
		file_exists($file) ? require_once $file : include 'template/default.tpl.php';
		! class_exists($className) && die('class '.$className.' not found.');
		$class = new $className();
		if(method_exists($class,$method) || (method_exists($class,'index') && $method = 'index')){
			$obj = new $class();
			$obj->$method();
		}else{
			die('method '.$method.' not found.');
		}
	}
}